#include <iostream>
#include <map>
#include <string>

using namespace std;

bool isPrime(int n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i += 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int prime(int num) {
    int diff1 = INT32_MAX, diff2 = INT32_MAX;
    int lower_prime, upper_prime;

    for (int i = num; i >= 100; i--) {
        if (isPrime(i)) {
            diff1 = num - i;
            lower_prime = i;
            break;
        }
    }

    for (int i = num + 1; i <= 999; i++) {
        if (isPrime(i)) {
            diff2 = i - num;
            upper_prime = i;
            break;
        }
    }

    if (diff1 <= diff2)
        return lower_prime;
    else
        return upper_prime;
}

int main() {
    map<string, int> digitMap = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    string w1, w2, w3;
    cin >> w1 >> w2 >> w3;

    if (digitMap.count(w1) == 0 or digitMap.count(w2) == 0 or digitMap.count(w3) == 0) {
        cout << "Wrong input";
        return 0;
    }

    int num = digitMap[w1] * 100 + digitMap[w2] * 10 + digitMap[w3];
    cout << prime(num);4
    21


    return 0;
}
